package net.pinnoocle.playadminpc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.admin.InformDetailVo;
import net.pinnoocle.playdao.entity.admin.InformListPageVo;
import net.pinnoocle.playdao.entity.admin.InformListSearchParams;
import net.pinnoocle.playdao.entity.admin.SaveInformParams;
import net.pinnoocle.playdao.entity.group.UpdateGroup;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playservice.service.impl.InformServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ye
 * @Description
 * @create 2021-11-03 9:31
 */
@RestController
@RequestMapping("/inform")
@Api(tags = "通知相关")
public class InformController {

    @Autowired
    InformServiceImpl informService;

    @GetMapping("informList")
    @ApiOperation("通知列表")
    public BaseResult<PageModel<InformListPageVo>> informList(InformListSearchParams searchParams){
        return new BaseResult<PageModel<InformListPageVo>>().ok(informService.informList(searchParams));
    }

    @PostMapping("saveInform")
    @ApiOperation("添加公告")
    public BaseResult<String> saveInform(@Validated @RequestBody SaveInformParams params){
        boolean result = informService.saveInform(params);
        if(result){
            return new BaseResult<String>().success("添加成功");
        }
        return new BaseResult<String>().error("添加失败");
    }

    @GetMapping("informDetail")
    @ApiOperation("公告详情")
    public BaseResult<InformDetailVo> informDetail(@RequestParam("informId") String informId){
        return new BaseResult<InformDetailVo>().ok(informService.informDetail(informId));
    }

    @PostMapping("updateInform")
    @ApiOperation("修改公告")
    public BaseResult<String> updateInform(@Validated({UpdateGroup.class}) @RequestBody SaveInformParams params){
        boolean result = informService.updateInform(params);
        if(result){
            return new BaseResult<String>().success("修改成功");
        }
        return new BaseResult<String>().error("修改失败");
    }

    @GetMapping("deleteInform")
    @ApiOperation("删除公告")
    public BaseResult<String> deleteInform(@RequestParam("informId") String informId){
        boolean result = informService.deleteInform(informId);
        if(result){
            return new BaseResult<String>().success("删除成功");
        }
        return new BaseResult<String>().error("删除失败");
    }
}
